package com.hainatong.jcmvvmbase.mainhome.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import com.blankj.utilcode.util.ToastUtils;
import com.hainatong.jcmvvmbase.Constants;
import com.hainatong.jcmvvmbase.MvvmLazyFragment;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.FragmentWelcomeBinding;
import com.hainatong.jcmvvmbase.mainhome.ComFragmentActivity;
import com.hainatong.jcmvvmbase.mainhome.WebViewActivity;
import com.hainatong.jcmvvmbase.mainhome.adapter.FunctionAdapter;
import com.hainatong.jcmvvmbase.mainhome.entity.FunctionEntity;
import com.hainatong.jcmvvmbase.utils.ClickUtil;
import com.hainatong.jcmvvmbase.widget.FireManeuverDialog;
import com.hainatong.mvvmbase.base.NoViewModel;
import com.hainatong.mvvmbase.utils.StatusBarUtils;

import android.graphics.Color;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;

public class WelcomeFragment extends MvvmLazyFragment<FragmentWelcomeBinding, NoViewModel>
{
    private List<FunctionEntity> functions;


    @Override
    protected void initParameters()
    {
        // 设置透明状态栏，兼容4.4
        // 设置状态栏为白底黑字
        //StatusBarUtils.setStatusBarColor(getActivity(), Color.parseColor("#265ceb"));
        StatusBarUtils.setStatusBarDarkFont(getActivity(), false);
    }

    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_welcome;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {

    }

    @Override
    protected void initView(View view)
    {


        functions = new ArrayList<>();
        functions.add( new FunctionEntity( getString(R.string.stock_out_in_mgr),"出库，入库，领用记录",R.mipmap.ic_item_ruku ) );
        functions.add( new FunctionEntity( getString(R.string.xiujia_mgr),"正常，临时，延期等休假",R.mipmap.ic_item_xiujia ) );
        functions.add( new FunctionEntity( "人员管理","人员相关的管理",R.mipmap.ic_item_worker ) );
        functions.add( new FunctionEntity( getString(R.string.work_mgr),"值班交接，上下船交接等",R.mipmap.ic_item_trans_work ) );
        functions.add( new FunctionEntity( "证书管理","各类设备证件",R.mipmap.ic_item_passport ) );
        functions.add( new FunctionEntity( getString(R.string.qshe_mgr),"各类模板表格",R.mipmap.ic_item_qshe) );

        FunctionAdapter adapter = new FunctionAdapter(functions);
        viewDataBinding.recyclerview.setAdapter(adapter);
        viewDataBinding.recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
        viewDataBinding.recyclerview.setHasFixedSize(true);

        adapter.setOnItemClickListener( (adapter1, view1, position) -> {

            if (ClickUtil.isFastClick(500, view1))
            {
                return;
            }

            if ( adapter.getItem( position ).getTitle().equals( getString(R.string.stock_out_in_mgr) ) )
            {
                Bundle bundle = new Bundle();
                bundle.putString(Constants.FRAGMNET_TYPE , Constants.FUN_STOCK_OUT_IN_MGR);
                ComFragmentActivity.start(getActivity(),bundle);
            }
            else if( adapter.getItem( position ).getTitle().equals( getString(R.string.xiujia_mgr) ))
            {
                Bundle bundle = new Bundle();
                bundle.putString(Constants.FRAGMNET_TYPE , Constants.FUN_HOLIDAY_MGR);
                ComFragmentActivity.start(getActivity(),bundle);
            }

            else if( adapter.getItem( position ).getTitle().equals( "人员管理" ))
            {
                WebViewActivity.start(getActivity(),"www.baidu.com");
            }
            else if( adapter.getItem( position ).getTitle().equals( "证书管理" ))
            {
                /*
                // scheme  传值 演示
                String uri = "luban://example/login?myArgs=87945645642";
                Intent luban = new Intent(Intent.ACTION_VIEW , Uri.parse( uri ));
                startActivity(luban);
                */


            }
            else if( adapter.getItem( position ).getTitle().equals( getString(R.string.work_mgr) ))
            {
                Bundle bundle = new Bundle();
                bundle.putString(Constants.FRAGMNET_TYPE , Constants.FUN_WORK_MGR);
                ComFragmentActivity.start(getActivity(),bundle);
            }
            else if( adapter.getItem( position ).getTitle().equals( getString(R.string.qshe_mgr) ))
            {
                Bundle bundle = new Bundle();
                bundle.putString(Constants.FRAGMNET_TYPE , Constants.FUN_QSHE_MGR);
                ComFragmentActivity.start(getActivity(),bundle);
            }

        } );



    }
}
